package src.dual_pointers;

/**
 * @author starsea
 * @date 2024-08-22 10:21
 */

public class Test07 {
    public static void main(String[] args) {
        int[] nums = {1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0};
        int k = 2;
        int m=longestOnes(nums,k);
    }

    public static int longestOnes(int[] nums, int k) {
        int n = nums.length;
        int ans = 1;
        int left = 0;
        int zero = 0;
        for (int right = 0; right < n; right++) {
            if (nums[right] == 0) {
                zero++;
            }
            while (zero > k) {
                if (nums[left++] == 0) {
                    zero--;
                }
            }
            ans = ans > right - left+1 ? ans : right - left+1;
        }
        return ans;
    }
}
